/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.httpsdk.http.face;

import java.util.HashMap;

import logic.constants.AppConfig;
import logic.constants.Const;
import logic.constants.DefaultConsts;
import logic.util.Util;

import org.json.JSONObject;

import android.content.Context;

import com.shwread.httpsdk.http.base.AbstractHttpPostDracom;
import com.shwread.httpsdk.http.callback.ActionListener;
import com.shwread.httpsdk.util.MD5;


/**
 * @Project： Shwread
 * @Title：ActivateEcardAction
 * @Description：电子券激活
 * @Author：wayne
 * @Date：2014年11月13日下午1:56:03
 */
public class ActivateEcardAction
        extends
        AbstractHttpPostDracom
{
	private String account;
	private String cardNum;
	private String cardPwd;
	private String type;
	private String fromType;
	private String acceptAccount;
	private String password;
	
	public ActivateEcardAction(Context context, String account, String cardNum, String cardPwd, String type, String fromType, String acceptAccount,String password, ActionListener actionListener) {
		super(context, "activateEcard.do", actionListener);
		this.account = account;
		this.cardNum = cardNum;
		this.cardPwd = cardPwd;
		this.type = type;
		this.fromType = fromType;
		this.acceptAccount = acceptAccount;
		this.password = password;
	}
	
	@Override
	public void getParameter(HashMap<String, String> parameter_map) {
		parameter_map.put("account", account);
		parameter_map.put("timeStamp", String.valueOf(timeStamp));
		parameter_map.put("cardNum", cardNum);
		parameter_map.put("cardPwd", cardPwd);
		parameter_map.put("activateType", type);
		parameter_map.put("fromType", fromType);
		if(Util.isNotEmpty(acceptAccount)){
			parameter_map.put("acceptAccount", acceptAccount);
		}
		if(Util.isNotEmpty(password)){
			parameter_map.put("password", MD5.MD5Encode(password));
		}
		parameter_map.put("enterpriseId", AppConfig.getEnterpriseId());
		parameter_map.put("cid", cid(account + Const.ACCOUNTTYPE + Const.CLIENTTYPE + timeStamp + AppConfig.getEnterpriseId() + cardNum + cardPwd + type + fromType));
	}
	
	@Override
	public void doResponseXml(String xml) {
		println(xml);
		int result = -1;
		try
		{
			JSONObject jsonObject = new JSONObject(xml);
			result = jsonObject.getInt("resultCode");
			if (result == DefaultConsts.OLD_USER_CODE || result==DefaultConsts.NEW_USER_CODE)
			{
//				listener.OK(xml);
				listener.OK(jsonObject.getString("returnObject"));
			}
			else
			{
				listener.ERROR(result, jsonObject.getString("returnObject"));
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	@Override
	protected void doRequestHeader(HashMap<String, String> header_map) {
		
	}
	
	@Override
	public void dispose() {
		
	}
	
}
